package modelo;
import org.hibernate.HibernateException;
import org.hibernate.Session;

import entities.FacturaEntity;
import entities.IngredienteEntity;
import entities.ProductoEntity;
import hbt.AbstractHibernateManager;

public class IngredienteDao extends AbstractHibernateManager{

	private static IngredienteDao instancia = null;
	
	public static IngredienteDao getInstancia() {
		if(instancia == null) {
			instancia = new IngredienteDao();
		}
		return instancia;
	}

			
			public void save (IngredienteEntity ingr){
				Session s = null;
				try {
					s=getNewSession();
					s.beginTransaction();
					s.persist(ingr);
					s.flush();
					s.getTransaction().commit();
					System.out.println("[Ingrediente SAVED ON TABLE Ingredientes]::OK");
				} catch (HibernateException e) {
					e.printStackTrace();
				} finally{
					closeSession(s);
				}
			}
			
			
			
			public IngredienteEntity obtenerIngrediente(Integer id) {
				Session s = null;
				IngredienteEntity ingreE = new IngredienteEntity();
				
				try {
					s = getNewSession();
					ingreE =  (IngredienteEntity) s.createQuery("FROM IngredienteEntity ing " +
											"WHERE ing.id = :id")
									  .setInteger("id", id).uniqueResult();
				} catch (HibernateException e) {
					e.printStackTrace();
				} finally{
					closeSession(s);
				}
				return ingreE;
			}

}
